package com.zzjson.mall.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzjson.mall.goods.model.Brand;
import com.zzjson.mall.goods.service.BrandService;
import com.zzjson.mall.util.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2020 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : TODO </li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2020年10月22日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
	@Autowired
	private BrandService brandService;

	@PostMapping
	public RespResult add(@RequestBody Brand brand) {
		brandService.save(brand);
		return RespResult.ok();
	}

	@PutMapping
	public RespResult update(@RequestBody Brand brand) {
		brandService.updateById(brand);
		return RespResult.ok();
	}

	@DeleteMapping("/{id}")
	public RespResult delete(@PathVariable(value = "id") String id) {
		brandService.removeById(id);
		return RespResult.ok();
	}

	@PostMapping(value = "/search")
	public RespResult<List<Brand>> queryList(@RequestBody Brand brand) {
		List<Brand> brands = brandService.queryList(brand);
		return RespResult.ok(brands);
	}

	/****
	 * 条件查询
	 */
	@PostMapping(value = "/search/{page}/{size}")
	public RespResult<Page<Brand>> queryPageList(
			@PathVariable(value = "page") Long page,
			@PathVariable(value = "size") Long size,
			@RequestBody Brand brand) {
		Page<Brand> pageInfo = brandService.queryPageList(brand, page, size);
		return RespResult.ok(pageInfo);
	}

}